<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>已安装插件列表</title>
    <link href="/static/bootstrap/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="../../css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="../../css/animate.min.css?v=4.0.0" rel="stylesheet">
    <link href="../../css/style.min.css?v=4.0.0" rel="stylesheet">

    <link href="../../css-user/develop.css" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="container-fluid topmenu">
        <h2><i class="fa fa-user"></i> 开发者账号</h2>
    </div>
    <div class="container-fluid account-edit">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>开发者基本信息</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">

                        <div class="form-horizontal">
                            <div class="form-group">
                                <label for="version" class="col-sm-2 control-label">
                                    开发者账号
                                    <p class="text-muted">developer</p>
                                </label>
                                <div class="col-sm-10" id="developer">
                                    <a class="btn btn-info btn-sm" href="#" id="loginDevloper" role="button">登录开发者</a>
                                    <p class="form-control-static" id="developer_user" style="display:none;"></p>
                                    <input type="hidden" value="" id="developer_webuid" />
                                </div>
                            </div>
                            <div id="isLogin" style="display: none;">
                                <div class="form-group">
                                    <label for="version" class="col-sm-2 control-label">
                                        手机号
                                        <p class="text-muted">mobile</p>
                                    </label>
                                    <div class="col-sm-10">
                                        <p class="form-control-static" id="mobile"></p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="version" class="col-sm-2 control-label">
                                        电子邮箱
                                        <p class="text-muted">E-mail</p>
                                    </label>
                                    <div class="col-sm-10">
                                        <p class="form-control-static" id="email"></p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="version" class="col-sm-2 control-label">
                                        最近登录时间
                                        <p class="text-muted">Lastlogin</p>
                                    </label>
                                    <div class="col-sm-10">
                                        <p class="form-control-static" id="Lastlogin"></p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="version" class="col-sm-2 control-label">
                                        最近登录IP
                                        <p class="text-muted">LastloginIP</p>
                                    </label>
                                    <div class="col-sm-10">
                                        <p class="form-control-static" id="Lastloginip"></p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <button type="button" class="btn btn-danger" id="exitDevloper"
                                            style="display:none;">退出登录</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row pluginbox" style="display: none;">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>我已发布的插件</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="buttons.html#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="buttons.html#">重新加载</a>
                                </li>
                                <li><a href="javascript:void(0);" class="close-link">关闭列表</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>

                    </div>
                    <div class="ibox-content">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>插件名</th>
                                    <th>中文名称</th>
                                    <th>简介</th>
                                    <th>版本号</th>
                                    <th class="text-center">最后更新时间</th>
                                    <th class="text-center">状态</th>
                                </tr>
                            </thead>
                            <tbody id="pluginList">

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="/static/jquery/jquery.min.js?v=2.1.4" type="text/javascript"></script>
    <script src="/static/bootstrap/bootstrap.min.js?v=3.3.7" type="text/javascript"></script>
    <script src="../../js/content.js?v=1.0.0"></script>

    <!-- 自定义全局js -->
    <script src="../../js-user/public.js" type="text/javascript"></script>

    <!-- 自定义js -->
    <script src="../../js-user/develop.js" type="text/javascript"></script>
    <script>
        $(function () {
            var loading = 0;
            show_developer = function (demo) {
                if (!$.isEmptyObject(demo)) {
                    $('#developer_user').show().html(demo.nickname);
                    $('#developer_webuid').val(demo.webuid);
                    $('#exitDevloper').show();
                    $('#isLogin').show();
                    $('.pluginbox').show();
                    $('#loginDevloper').hide();

                    loading = parent.layer.load(1, { shade: [0.1, '#fff'] });
                    $.ajax_developInfo(demo.webuid, get_developInfo);
                    $.ajax_developPlugin(demo.webuid, get_develoPlugin);
                } else {
                    $('#loginDevloper').show();
                    $('#developer_user').hide();
                    $('#exitDevloper').hide();
                    $('#isLogin').hide();
                    $('.pluginbox').hide();
                    $('#developer_webuid').val('');
                }
            };

            // 已获取开发者基本信息
            get_developInfo = function (data) {
                $('#mobile').html(data.mobile);
                $('#email').html(data.email);
                $('#Lastlogin').html(data.last_login_time);
                $('#Lastloginip').html(data.last_login_ip);
            };

            // 已获取到开发者插件列信息
            get_develoPlugin = function (data) {
                var tabhtml = '';
                if ($.isEmptyObject(data)) {
                    tabhtml += '<tr><td colspan="7" class="text-center">您暂时还没有发布任何插件。</td></tr>';
                } else {
                    $.each(data, function (i, n) {
                        tabhtml += '<tr><td>' + i + '</td><td>' + n.name + '</td>';
                        tabhtml += '<td>' + n.displayname + '</td><td>' + n.description.substr(0, 50);
                        if (n.description.length > 50) { tabhtml += '…'; }
                        tabhtml += '</td><td>' + n.version + '</td>';
                        tabhtml += '<td class="text-center">' + n.updatetime + '</td>';
                        tabhtml += '<td class="text-center">';
                        if (n.stauts == 1) {
                            tabhtml += '<span class="label label-success">通过</span>';
                        } else {
                            tabhtml += '<span class="label label-danger">待审核</span>';
                        }
                        tabhtml += '</td></tr>';
                    });
                }
                $('#pluginList').html(tabhtml);
                parent.layer.close(loading);
            };

            // 加载开发者信息
            $.ajax_develop(function (data) {
                var demo = {};
                if (!$.isEmptyObject(data)) {
                    demo = {
                        webuid: data.userid,
                        nickname: data.username
                    };
                }
                show_developer(demo);
            });

            // 登录开发者账号
            $('#loginDevloper').click(function () {
                var _this = $(this);
                _this.attr({ 'disabled': 'disabled' }).text('开始登录…');
                $.login_develop(function (data) {
                    var demo = {};
                    if (!$.isEmptyObject(data)) {
                        demo = {
                            webuid: data.webuid,
                            nickname: data.nickname
                        }
                    }
                    show_developer(demo);
                    _this.removeAttr('disabled').text('登录开发者');
                });
            });

            // 退出开发者账号
            $('#exitDevloper').click(function () {
                var _this = $(this);
                _this.attr({ 'disabled': 'disabled' });

                parent.swal({
                    title: "您确定要退出吗",
                    text: "退出后无法管理插件，请谨慎操作！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的，我要退出！",
                    cancelButtonText: "让我再考虑一下…",
                    closeOnConfirm: false
                }, function (a) {
                    if (a) {
                        $.logout_develop(function (data) {
                            if (data.code == '0000') {
                                show_developer({});
                            }
                            _this.removeAttr('disabled');
                        });
                    } else {
                        _this.removeAttr('disabled');
                    }
                    parent.swal.close();
                });
            });
        });
    </script>
</body>

</html>